package com.nhjf.dao.withdraw;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.withdraw.Withdraw;
import com.nhjf.pojo.qo.withdraw.WithdrawQo;
@Repository
public class WithdrawDao extends BaseDao<Withdraw, WithdrawQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, WithdrawQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {
			criteria.setFetchMode("oranizationAccount", qo.isSeachOranizationAccount()?FetchMode.JOIN:FetchMode.SELECT);	
			if(qo.getConfirmTheTime()!=null) {
				criteria.add(Restrictions.eq("confirmTheTime",qo.getConfirmTheTime()));
			}
			if(qo.getOranizationAccountId()!=null) {
				criteria.add(Restrictions.eq("oranizationAccount.id",qo.getOranizationAccountId()));
			}
			if(StringUtils.isNotBlank(qo.getPayeeName())) {
				criteria.add(Restrictions.eq("payeeName",qo.getPayeeName()));
			}
			if(qo.getStatus()!=null) {
				criteria.add(Restrictions.eq("status",qo.getStatus()));
			}
			if(qo.getWithdrawalAmount()!=null) {
				criteria.add(Restrictions.eq("withdrawalAmount",qo.getWithdrawalAmount()));
			}
			if(qo.getWithdrawId()!=null) {
				criteria.add(Restrictions.eq("id",qo.getWithdrawId()));
			}
			if(StringUtils.isNotBlank(qo.getZfbAccountNumber())) {
				criteria.add(Restrictions.eq("zfbAccountNumber",qo.getZfbAccountNumber()));
			}
			 criteria.addOrder(Order.desc("creaTime"));
		}
		return criteria;
	}

	@Override
	protected Class<Withdraw> getEntityClass() {
		// TODO Auto-generated method stub
		return Withdraw.class;
	}

}
